package com.peanut.boot;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;


/**
 * @className: com.peanut.boot-> Junit5Assertions
 * @description: 断言练习
 * @author: chenhs
 * @createDate: 2021-12-05 13:38
 * @version: 1.0
 */
@Slf4j
public class Junit5Assertions1 {
    @DisplayName("测试简单断言")
    @Test
    void testSimpleAssertions() {
        int cal = cal(1, 2);
        //验证字面内容是否一致。
        Assertions.assertEquals(3, cal);
        // 期望值，实际值，不符合预期是填写的提示
        //  Assertions.assertEquals(5, cal,"加法计算错误");
        Object o = new Object();
        Object o2 = new Object();
        // 验证引用地址是否一致
        Assertions.assertSame(o, o2, "对象不一致-");
    }

    @DisplayName("测试数组断言")
    @Test
    void testAssertionsArray() {
        Assertions.assertArrayEquals(new int[]{1,2,3,4},new int[]{1,2,2,4},"数组不一致");
    }

    @DisplayName("测试组合断言")
    @Test
    void testGroupAssertions() {
//        当申明的所有断言全部赌满足是组合断言才为真
        Assertions.assertAll("组合断言名称",
                ()->Assertions.assertEquals(1,1),
                ()->Assertions.assertEquals(1,1),
                ()->Assertions.assertEquals(1,1),
                ()->Assertions.assertEquals(1,1),
                ()->Assertions.assertEquals(1,2),
                ()->Assertions.assertEquals(1,1)
        );
    }

    @DisplayName("测试异常断言")
    @Test
    void testExceptionAsstertion() {
//        逻辑是我猜测这里一定会出现异常，如果这里真的出现的我猜测的异常 断言成功，不出异常时断言失败。请注意。
        Assertions.assertThrows(ArithmeticException.class, () -> {
            int a=10 / 0;
        }, "为什么分母为0可以除断？？？");
    }
    @DisplayName("测试前置条件")
    @Test
    void testassumptions() {
        Assumptions.assumeTrue(false,"结果不是true");
        Assumptions.assumeFalse(true,"结果不是 false");
        log.info("前置条件不满，后续代码不执行。");
    }
    // 加法
    int cal(int i, int j) {
        return i + j;
    }


}
